public without sharing class SalesReceiptDetailHandler{
   ///更新销售收款明细时 根据业务员编号查找用户修改Owner
    public static void changeOwner(List< SalesReceiptDetail__c> list_new){
    	Map<String,Id> owners = new Map<String,Id>();
      Map<String,Id> managers = new Map<String,Id>();

        for(SalesReceiptDetail__c s: list_new){
        	if(s.ywy_number__c != null){
                String uid = s.ywy_number__c;
                if(uid.length()>4)uid = uid.substring(uid.length()-4,uid.length());
                owners.put(uid,null);
            }
        }
        Map<String ,String>comMap = new Map<String,String>();
       for(String corps: System.Label.Corp_SalesReceipt.split(',',-1)){
       		List<String>corp = corps.split('-',-1);
           if(corp.size()>1){
           		comMap.put(corp[0],corp[1]);
           }
       }


        ///查询用户
       for(User u: [select Id,ExuserCode__c ,ManagerId from User where IsActive = true and ExuserCode__c in :owners.keySet()]){
       		String uid = '0000000' + u.ExuserCode__c;
            uid = uid.substring(uid.length() - 4,uid.length());
             
           if(owners.containsKey(uid)){
            owners.put(uid,u.Id);
            managers.put(uid, u.ManagerId);
          }

       }
       ///改变OwnerId 
        for(SalesReceiptDetail__c s: list_new){
               String uid = s.ywy_number__c;
                if(uid.length()>4)uid = uid.substring(uid.length()-4,uid.length());
            System.debug(Owners + '   ' + s);
        	if(owners.containsKey(uid) && owners.get(uid) != null){
               s.OwnerId = owners.get(uid);
               s.OwnerManager__c = managers.get(uid);
               
            }else{
               if(comMap.containsKey(s.corp_name__c)){
               	 s.OwnerId = comMap.get(s.corp_name__c);
               }
            }
        }
        
    
    }

}